package com.ruoyi.system.mapper.waterMapper;

import com.ruoyi.system.domain.waterEnity.BuildingEntity;
import com.ruoyi.system.domain.waterEnity.DistributionInfoBo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface DistributionMapper {
    //查看配送信息
    //查询全部的订单，此方法配送员
    @Select("select o.id,o.pay_time,d.delivery_time,o.user_name,o.receiving_address,o.receiving_phone,o.building,(select" +
            " username from water.user where o.user_id=user.id) as deliveryman,o.state from water.order o left join " +
            "water.distribution d " + "on o.id=d.order_id where (o.state=1 or o.state=2) order by pay_time DESC")
    List<DistributionInfoBo> selectDistribution();
    //按收货状态查看配送信息
    @Select("select o.id,o.pay_time,d.delivery_time,o.user_name,o.receiving_address,o.receiving_phone,o.building,(select " +
            "username from water.user where o.user_id=user.id) as deliveryman,o.state from water.order o left join water.distribution d " +
            "on o.id=d.order_id where  o.state=#{state} order by pay_time desc")
    List<DistributionInfoBo> selectDistributionByState(String state);
    //根据手机号查看配送信息
    @Select("select o.id,o.pay_time,d.delivery_time,o.user_name,o.receiving_address,o.receiving_phone,o.building,(select username " +
            "from water.user where o.user_id=user.id) as deliveryman,o.state from water.order o left join water.distribution d on o.id=d.order_id " +
            "where (o.state=1 or o.state=2) and receiving_phone = #{phone} order by pay_time desc")
    List<DistributionInfoBo> selectDistributionByPhone(String phone);
    //根据地点查看配送信息
    @Select("select o.id,o.pay_time,d.delivery_time,o.user_name,o.receiving_address,o.receiving_phone,o.building,(select " +
            "username from water.user where o.user_id=user.id) as deliveryman,o.state from water.order o left join water.distribution d " +
            "on o.id=d.order_id where (o.state=1 or o.state=2) and  building = #{building} order by pay_time desc")
    List<DistributionInfoBo> selectDistributionByBuilding(String building);
    //修改配送信息
    @Update("update water.order set state = #{state} order by pay_time desc")
    int updateOrderState(int state);
    //删除配送信息
    @Delete("delete from water.order where id = #{id}")
    int deleteOrderByID(int id);
    //导出配送数据
    @Select("select o.id,o.pay_time,d.delivery_time,o.user_name,o.receiving_address,o.receiving_phone,o.building,(select username from water.user where o.user_id=user.id) as deliveryman,o.state from water.order o left join water.distribution d on o.id=d.order_id where o.id in" +
            "<foreach collection='array' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            " order by pay_time desc"+
            "</script>")
    List<DistributionInfoBo> selectOrderByIds(Long[] ids);
    //删除订单数据
    @Select("delete from water.order where id in" +
            " <foreach collection='array' item='id' open='(' separator=',' close=')'>" +
            "#{id}"+
            "</foreach>" +
            "</script>")
    int deleteOrderByIds(Long[] ids);
    @Select("select * from water.building")
    List<BuildingEntity> selectBuilding();
}
